<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<jsp:include page="../../import.jsp" flush="true" />
<jsp:include page="../common/warrantCommFunction.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="ligerForm">
				<div class="fieldset1 tabel_col clearFix">
					<div class="caption">
						<span class="title">基本信息</span>
						<input type="hidden" id="flag" name="flag"  value="${flag}" /> 
					</div>
					<div class="fieldBox col_50">
						<div class="label">事业部</div>
						<div class="field">
							<input name="oldbussDepartment" id="oldbussDepartment"   type="hidden">
							<select id="bussDepartment"  name="bussDepartment"  ligerui="width: 160">
								<option value="">请选择</option>
								<c:forEach items="${buOrgCdList}" var="item">
									<option <c:if test="${item.key == bussDepartment}"> selected </c:if> value="${item.key}">${item.value}</option>
								</c:forEach>
							</select>
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<input  id="oldproCompany" name="oldproCompany" value="${proCompany}" type="hidden">
					<div class="fieldBox col_33" id="cstMgrOrgCdId" >
		                <div class="label">所属省公司</div>
		                <div class="field">
		                    <input  id="proCompany" name="proCompany" type="text" class="ui-textbox" >
		                    <span class="requiredSymbol">*</span>
		                </div>
		            </div>
					<div class="fieldBox col_100">
						<div class="label">归档天数</div>
						<div class="field">
							<input type="text" id="arcDay" name="arcDay"  ligerui="width: 120" value="${arcDay}" onblur="if(/\D/.test(this.value)){alert('只能输入数字');this.value='';}">
							天<span class="requiredSymbol">*</span>
						</div>
					</div>
				</div>
				<div class="btnsBox">
					<span id="saveBtn" class="sq-button sq-button-round" onclick="save();">保存</span>
					<span id="closeBtn" class="sq-button sq-button-round" onclick="Remove_navTab();">关闭</span>
				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript">
		$(function() {
			initOrgTree();
			$("#ligerForm").ligerForm({
				validate: true
			});
			initGrid();//初始化明细
// 			liger.get("bussDepartment").selectValue("${bussDepartment}");//事业部
// 			liger.get("proCompany").selectValue("${proCompany}");//省公司
			$("#oldbussDepartment").val($("#bussDepartment").val());
			if($("#flag").val() ==1){
				document.getElementById("saveBtn").style="display:none";
			}
	    });
	
		
		//初始化明细
		function initGrid(){
		}
		
		//保存
		function save(){
			var ligerForm = liger.get("ligerForm");
			if (!ligerForm.valid()) {
				$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
				return false; 
			}
			if($.trim($("#bussDepartment").val()) == ""){
				$.ligerDialog.SQalert({content: "请选择事业部",SQ_type: "warning"});
				return false;
			}
			if($("#proCompany").val() == "null" || $("#proCompany").val() == ""){
				$.ligerDialog.SQalert({content: "请选择省公司",SQ_type: "warning"});
				return false;
			}
			if($.trim($("#arcDay").val()) == ""){
				$.ligerDialog.SQalert({content: "请填写归档天数",SQ_type: "warning"});
				return false;
			}
			var data = ligerForm.getData();//表数据
			data["json"] = JSON.stringify(data);
			var oldproCompany = $("#oldproCompany").val();
			var oldbussDepartment = $("#oldbussDepartment").val();
			var wait_dialog = null;
			var id="${id}";
			$.ajax({
				type: 'post',
				dataType: 'json',
				data: data,
				url: '<%=path%>/archive/arcDayMaintain/add.do?id='+id+"&oldproCompany="+oldproCompany+"&oldbussDepartment="+oldbussDepartment,
				beforeSend: function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
				},success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
							$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
							if(id == "") {
								Remove_navTab();//新增，关闭当前页面
							}
							if($("#flag").val() ==2){//修改页面修改完隐藏保存按钮
	 							document.getElementById("saveBtn").style="display:none";//提示不允许修改后，隐藏保存按钮
							}
					}else{
						$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
						if($("#flag").val() ==2){
 							document.getElementById("saveBtn").style="display:none";//提示不允许修改后，隐藏保存按钮
						}
					}
				},error:function (XMLHttpRequest, textStatus, errorThrown) { 
					wait_dialog.close();
					$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
				} 
			});
		}
		function initOrgTree(){
	    	var params = {};
	    	 searchOrgTree = $("#proCompany").ligerComboBox({
	    		 width: 480,
	             selectBoxWidth: 480,
	             selectBoxHeight: 150,
	             //限制只能选叶节点，父节点不能点击
	             treeLeafOnly: false,
	             valueField: 'orgCd',
	             textField: 'orgDispNm',
	             showTreePath: true,
	             tree: {
	                 ajaxType: 'get',
	                 idFieldName:'orgCd',
	                 textFieldName: 'orgDispNm',
	                 checkbox: false,
	                 parentIcon: "none",
	                 childIcon: "none",
	                 needCancel : false
	             }
	         });
	    	 $.ajax({
	     		type: 'get',
	     		dataType:'json',
	     		data: params,
	     		url: '<%=path%>/warrant/warrantfilemanage/searchBuOrgTree.do',
	     		success:function(msg){
	     			if(msg.success == 1){
	     				searchOrgTree.treeManager.setData(msg.data);
	     				searchOrgTree.clear();
	     				searchOrgTree.setValue('${proCompany}');
	     			}else{
	     				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	     			}
	     		}
	     	});

	    }    
		    
	</script>
</body>
</html>